<style>
    @media screen and (max-width: 500px) {
        .layui-layer.layui-layer-page {
            width: 100% !important;
            overflow: hidden !important;
            left: 0 !important;
        }

        .layui-layer-title {
            width: 100% !important;
            box-sizing: border-box;
        }

        .layui-layer-content {
            width: 100% !important;
        }

    }
</style>
<form class="layui-form seller-form" action="">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label seller-inline-2">支付单号：</label>
            <div class="layui-input-inline">
                <input type="text" name="payment_id" lay-verify="title" placeholder="请输入支付单号" autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label seller-inline-2">第三方单号：</label>
            <div class="layui-input-inline">
                <input type="text" name="trade_no" lay-verify="title" placeholder="请输入第三方单号" autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label seller-inline-2">支付时间：</label>
            <div class="layui-input-inline">
                <input type="text" name="date" id="date" placeholder="开始时间 到 结束时间" autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label seller-inline-2">用户手机号码：</label>
            <div class="layui-input-inline">
                <input type="text" name="mobile" lay-verify="title" placeholder="请输入完整手机号码" autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label seller-inline-2">支付状态：</label>
            <div class="layui-input-inline">
                <select name="status" lay-verify="">
                    <option value=""></option>
                    <option value="1">待支付</option>
                    <option value="2">支付成功</option>
                    <option value="3">其他</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label seller-inline-2">单据类型：</label>
            <div class="layui-input-inline">
                <select name="type" lay-verify="">
                    <option value=""></option>
                    {foreach $bill_payments_type as $key=>$vo}
                    <option value="{$key}">{$vo}</option>
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="*"><i
                    class="iconfont icon-chaxun"></i>筛选</button>
            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="export-payments"><i
                    class="iconfont icon-clouddownload" style="font-size: 20px !important;"></i>导出</button>
        </div>
    </div>
</form>
<div class="table-body">
    <table id="billPayments" lay-filter="test"></table>
</div>
<div id="exportPayments" style="display: none;">
    <form class="layui-form export-form" action="">
        <div class="layui-form-item">
            <div class="layui-margin-10">
                <blockquote class="layui-elem-quote layui-text">
                    请先选中或筛选要导出的订单
                </blockquote>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">任务名称：</label>
                <input type="text" name="taskname" lay-verify="title" style="width:200px;" placeholder="请输入任务名称"
                    autocomplete="off" class="layui-input">
            </div>
        </div>
    </form>
</div>



<script>
    layui.use(['form', 'layedit', 'laydate', 'table'], function () {
        //时间插件
        layui.laydate.render({
            elem: '#date',
            range: '到',
            format: 'yyyy-MM-dd'
        });
        layui.table.render({
            elem: '#billPayments',
            height: 'full-115',
            cellMinWidth: '80',
            page: 'true',
            limit: '20',
            url: "{:url('billPayments/index')}?_ajax=1",
            id: 'billPayments',
            cols: [[
                { type: 'checkbox' },
                { field: 'payment_id', width: 200, sort: true, title: '支付单号' },
                { field: 'status', width: 100, title: '状态' },
                { field: 'payment_code', width: 120, title: '支付方式' },
                { field: 'type', width: 100, title: '单据类型' },
                { field: 'user_id', width: 100, minWidth: 50, title: '用户' },
                { field: 'money', width: 80, title: '金额' },
                { field: 'gift', width: 100, title: '赠送金额' },
                { field: 'trade_no', width: 260, title: '第三方单号' },
                { field: 'utime', width: 160, title: '支付时间' },
                {
                    field: 'operating', title: '操作', width: 100, align: 'center', templet: function (data) {
                        var html = '';
                        html += '<a  class="layui-btn layui-btn-xs option-view layui-btn-primary" data-id="' + data.payment_id + '">明细</a>';
                        return html;
                    }
                },
            ]]
        });
        layui.form.on('submit(*)', function (data) {
            layui.table.reload('billPayments', {
                where: data.field
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        //查看操作
        $(document).on('click', '.option-view', function () {
            JsGet("{:url('billPayments/view')}?payment_id=" + $(this).attr('data-id'), function(e){
                if ((e.hasOwnProperty('status') && !e.status) || (e.hasOwnProperty('code') && e.code == 0)) {
                    layer.msg(e.msg); return false;
                }

                if (e.status) {
                    window.box = layer.open({
                        type: 1,
                        content: e.data,
                        area: ['600px', '480px'],
                        title: '支付单查看'
                    });
                } else {
                    layer.msg(e.msg);
                }
            });
        });
        //支付单导出
        layui.form.on('submit(export-payments)', function (data) {
            layer.open({
                type: 1,
                title: '支付单导出',
                area: ['400px', '248px'], //宽高
                btn: ['确定', '取消'],
                content: $("#exportPayments").html(),
                success: function () {
                    $(':focus').blur();
                    this.enterEsc = function(event){
                        if(event.keyCode === 13){
                            if(!$(".layui-layer-btn0").hasClass("layui-btn-disabled")){
                                $(".layui-layer-btn0").addClass("layui-btn-disabled");
                                //判断是否有选中
                                var checkStatus = layui.table.checkStatus('billPayments');
                                var checkData = checkStatus.data;
                                var length = checkStatus.data.length;
                                var ids = [];
                                if (length) {
                                    $.each(checkData, function (i, obj) {
                                        ids.push(obj.payment_id);
                                    });
                                }

                                //判断是否有选中
                                var filter = $(".seller-form").serialize();
                                filter += '&ids=' + ids;
                                $(".export-form:last").append("<input type='hidden' name='filter' value='" + filter + "'>");
                                var data = $(".export-form:last").serializeArray();

                                if($.trim(data[0]['value']) == '') {
                                    layer.msg('请填写任务名称！', { time: 1300 });
                                    $(".layui-layer-btn0").removeClass("layui-btn-disabled");
                                    return false;
                                }

                                data.push({ 'name': 'model', 'value': 'BillPayments' });

                                JsPost("{:url('Ietask/export')}", data, function (res) {
                                        layer.msg(res.msg, { time: 1500 }, function () {
                                            if (res.status) {
                                                layui.table.reload('billPayments');
                                                layer.closeAll();
                                                //执行跳转
                                                var topLayui = parent === self ? layui : top.layui;
                                                topLayui.index.openTabsPage('/manage/ietask/index.html', '导入导出');
                                            } else {
                                                $(".layui-layer-btn0").removeClass("layui-btn-disabled");
                                            }
                                        });
                                    }
                                );
                            }
                            return false; //阻止系统默认回车事件
                        }
                    };
                    $(document).on('keydown', this.enterEsc);	//监听键盘事件，关闭层
                },
                yes: function () {
                    if(!$(".layui-layer-btn0").hasClass("layui-btn-disabled")){
                        $(".layui-layer-btn0").addClass("layui-btn-disabled");
                        //判断是否有选中
                        var checkStatus = layui.table.checkStatus('billPayments');
                        var checkData = checkStatus.data;
                        var length = checkStatus.data.length;
                        var ids = [];
                        if (length) {
                            $.each(checkData, function (i, obj) {
                                ids.push(obj.payment_id);
                            });
                        }

                        //判断是否有选中
                        var filter = $(".seller-form").serialize();
                        filter += '&ids=' + ids;
                        $(".export-form:last").append("<input type='hidden' name='filter' value='" + filter + "'>");
                        var data = $(".export-form:last").serializeArray();

                        if($.trim(data[0]['value']) == '') {
                            layer.msg('请填写任务名称！', { time: 1300 });
                            $(".layui-layer-btn0").removeClass("layui-btn-disabled");
                            return false;
                        }

                        data.push({ 'name': 'model', 'value': 'BillPayments' });

                        JsPost("{:url('Ietask/export')}", data, function (res) {
                                layer.msg(res.msg, { time: 1500 }, function () {
                                    if (res.status) {
                                        layui.table.reload('billPayments');
                                        layer.closeAll();
                                        //执行跳转
                                        var topLayui = parent === self ? layui : top.layui;
                                        topLayui.index.openTabsPage('/manage/ietask/index.html', '导入导出');
                                    } else {
                                        $(".layui-layer-btn0").removeClass("layui-btn-disabled");
                                    }
                                });
                            }
                        );
                    }
                }, btn2: function () {
                    layer.closeAll();
                }, end: function(){
                    $(document).off('keydown', this.enterEsc);	        //解除键盘关闭事件
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });
</script>